package 常用方法.字符串查找;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-06-20
 * Time: 11:30
 */
//字符串查找也是字符串中非常常见的操作，String类提供的常用查找的方法：
public class Test {
    public static void main(String[] args) {
        String s = "ababcabcd";

        //char charAt(int index):
        System.out.println(s.charAt(3));//b

        //int indexOf(int ch):
        System.out.println(s.indexOf('c'));//4
        //int indexOf(int ch, int fromIndex):
        System.out.println(s.indexOf('c', 3));//4
        //int indexOf(String str):
        System.out.println(s.indexOf("abc"));//2
        //int indexOf(String str, int fromIndex):
        System.out.println(s.indexOf("abc", 3));//5

        //int lastIndexOf(int ch):
        System.out.println(s.lastIndexOf('c'));//7
        //int lastIndexOf(int ch, int fromIndex):
        System.out.println(s.lastIndexOf('c', 3));//-1
        //int lastIndexOf(String str):
        System.out.println(s.lastIndexOf("abc"));//5
        //int lastIndexOf(String str, int fromIndex):
        System.out.println(s.lastIndexOf("abc", 3));//2

    }
}

//注意：上述方法都是实例方法。